<?php 
/**
*
*总部信息统计
*
*/
require('./include/init.php');
date_default_timezone_set('Asia/Shanghai');
//连接数据库
$mysql=mysql::getIns();
$sql="select * from alldev";
// $data=$mysql->getAll($sql);
// print_r($data);
//统计当前在线人数    (在线人数为当前时间的十分钟之前到现在的人数)
$maxtime=time();
$mintime=$maxtime-10*60;


$t = time();
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
/*echo $maxtime . '<br />';
echo $mintime;
exit;*/
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $mintime and timestamp < $maxtime and shop <> 'Audi City BeiJing'";
$allnow=$mysql->getOne($sql);
// print_r($allnow);
// exit;
//统计当天累计人数数

$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $start and timestamp < $end and shop <> 'Audi City BeiJing'";
$allday=$mysql->getOne($sql);
// echo $allday;

//当前首次进店人数,通过字段visittimes为1来进行判断
$sql="select count(*) from alldev where whitelist <> '1' and visittimes=1 and timestamp > $mintime and timestamp < $maxtime and shop <> 'Audi City BeiJing'";
$first=$mysql->getOne($sql);
// echo $first;
// exit;
//今天多次进店人数
$sql="select count(*) from alldev where whitelist <> '1' and visittimes <> 1 and timestamp > $mintime and timestamp < $maxtime and shop <> 'Audi City BeiJing'";
$second=$mysql->getOne($sql);

//统计当前销售区
$sql="select count(*) from alldev where whitelist <> '1' and timestamp > $mintime and timestamp < $maxtime and shop <> 'Audi City BeiJing' and area in ('销售区','展厅区','精品区')";
$sale=$mysql->getOne($sql);

// print_r($sale);
// exit;
//统计今天售后区
$service=$allnow-$sale;

//统计登陆人数
$sql="select count(*) from alldev where whitelist <> '1' and isOL=1 and timestamp > $mintime and timestamp < $maxtime and shop <>'Audi City BeiJing'";
$login=$mysql->getOne($sql);
// echo $login;

//统计未登陆人数
$sql="select count(*) from alldev where whitelist <> '1' and isOL=2 and timestamp > $mintime and timestamp < $maxtime and shop <>'Audi City BeiJing'";
$nolog=$mysql->getOne($sql);
// echo $nolog;

//统计历史进店人数
$sql="select count(*) from alldev where whitelist <> '1' and shop <>'Audi City BeiJing'";
$history=$mysql->getOne($sql);
// exit;
require(ROOT . 'view/iwocar5/National_Main.html');
 ?>